﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Data;
using System.Windows;

namespace PTExpress.Converters
{
    class TextBoxCompleteValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string result = string.Empty;
            if (value == null)
                return result;
            if (value.ToString().ToUpper().Equals("TEXT"))
                return result;
            try
            {
                if (value.ToString().IndexOf("KH") == 0)
                {
                    DataTable tb = null;// Models.KhachHangModel.GetKhachHang(value.ToString());
                    if (tb.Rows.Count > 0)
                        result = tb.Rows[0]["tenkh"].ToString();
                }
                else
                    if (value.ToString().IndexOf("NV") == 0)
                    {
                        DataTable tb = null;// Models.NhanVienModel.GetNhanVien(value.ToString());
                        if (tb.Rows.Count > 0)
                            result = tb.Rows[0]["tennv"].ToString();
                    }
                    else
                        if (value.ToString().IndexOf("P") == 0)
                        {
                            result = value.ToString();
                        }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "QLKS", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
